package com.ego.dao.impl;

import com.ego.dao.LoginDao;
import com.ego.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author 袁梦达 2019012364
 */
public class LoginDaoImpl implements LoginDao {

    @Override
    public boolean checkUser(String number, String password){
        Connection connection = JDBCUtils.getConnection();
        PreparedStatement statement = null;
        try {
            String sql = "select * from user where number = ? and password = ?";
            statement = connection.prepareStatement(sql);
            statement.setString(1, number);
            statement.setString(2, password);
            if(statement.executeQuery().next()){
                return true;
            }
            return false;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.close(statement, connection);
        }
        return false;
    }

}
